﻿#if UNITY_EDITOR


using System.IO;
using UnityEditor;
using UnityEngine;

namespace BF.Lunch
{
    public class LaunchSetting : ScriptableObject
    {
        [Header("Lunch Scene Name")]
        public SceneAsset lunchScene;


        private const string LUNCH_SETTING_PATH = "Assets/__BF/Editor/LaunchSetting/";
        private const string LUNCH_SETTING_NAME = "LaunchSetting";

        private static readonly string LUNCH_SETTING_FILE_PATH = Path.Combine(LUNCH_SETTING_PATH, LUNCH_SETTING_NAME + ".asset");

        public static LaunchSetting GetInstance()
        {
            LaunchSetting setting = AssetDatabase.LoadAssetAtPath<LaunchSetting>(LUNCH_SETTING_FILE_PATH);
            if (setting == null)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(LUNCH_SETTING_PATH);
                if (!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }

                setting = CreateInstance<LaunchSetting>();
                AssetDatabase.CreateAsset(setting, LUNCH_SETTING_FILE_PATH);
                AssetDatabase.Refresh();
            }

            return setting;
        }


        [MenuItem("BF/Lunch/Edit Lunch Setting", false, 0)]
        private static void EditSetting()
        {
            Selection.activeObject = GetInstance();
        }


        [MenuItem("BF/Lunch/Clear Lunch Setting", false, 0)]
        private static void ClearSetting()
        {
            GetInstance().lunchScene = null;
        }
    }
}
#endif